<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="root"></div>

    <script src="../lib/react.js"></script>
    <script src="../lib/react-dom.js"></script>
    <script src="../lib/babel.js"></script>

    <script type="text/babel">
      // 1.创建root
      const root = ReactDOM.createRoot(document.querySelector("#root"));

      // 2.创建类组件
      class App extends React.Component {
        constructor() {
          super(); //继承了就要调用super
          this.state = {
            //数据固定放在state中
            count: 0,
          };
        }
        dowClick() {
          console.log(this);

          this.setState({
            count: this.state.count - 1,
          });
        }
        upClick() {
          this.setState({
            count: this.state.count + 1,
          });
        }

        render() {
          const { count } = this.state;
          return (
            <div>
              <h2>{count}</h2>
              <button onClick={this.upClick.bind(this)}>+1</button>
              <button onClick={this.dowClick.bind(this)}>-1</button>
            </div>
          );
        }
      }

      // 3.渲染函数
      root.render(<App />);
    </script>
  </body>
</html>
